function count(mixed_var, mode) {
	var key, cnt = 0;
	if (mode == 'COUNT_RECURSIVE')
		mode = 1;
	if (mode != 1)
		mode = 0;
	for (key in mixed_var) {
		cnt++;
		if (mode == 1
				&& mixed_var[key]
				&& (mixed_var[key].constructor === Array || mixed_var[key].constructor === Object)) {
			cnt += count(mixed_var[key], 1);
		}
	}
	return cnt;
}

$(function () {

$('#callform dl').append('<dt class="hover" style="display:none"></dt>');
$('#callform').submit(function(){
	
	$('#callform .hover').show();
	var email=$('#email').val();
	var name=$('#name').val();
	var text=$('#text').val();
	
	$.post($(this).attr('action'),{email:email,name:name,text:text},function(data){
		
		$('.errors').remove();
		if(data['success'] == false) {
			
			for (i in data['errors']) {
				if (count(data['errors'][i]) > 0) {
					err = "<ul class='errors'>";
				} else {
					err = "";
				}
				for (j in data['errors'][i]) {
					err += "<li>" + data['errors'][i][j] + "</li>";
				}
				if (count(data['errors'][i]) > 0) {
					err += "</ul>";
					$('#'+i+"-element").append(err);
				}
			}
		}else{
			var h=$('#callform').height();
			$('#callform').css('height',h);
			$('#callform').html('<h4>'+data['message']+'</h4>');
			
			$('#email').val('');
			$('#name').val('');
			$('#text').val('');
		} 
		$('#callform .hover').hide();
	});
	
	
	
	return false;
});




});